<?php 
  require(dirname(__FILE__)."/global.php");
  require(ROOT."/admin/isLogin.php");
  
  $submit = $_POST['submit'];
  if(isset($submit))
  {   
      $dels = $_POST['del'];
      $ipAddrs = $_POST['ipAddr'];
      $ipAlerts = $_POST['ipAlert'];
                                                
      foreach($dels as $del){
          $sql = "delete from talking_ipfilter where IPID=$del";
          $db->execute($sql);
      }
      
      for($i=0;$i<count($ipAddrs);$i++){
          if(DataConverter::isIP($ipAddrs[$i])){
              $ipPos = DataConverter::getIpPlace($ipAddrs[$i]);
              $sql = "insert into talking_ipfilter(IPAddr,IPPosition,IPAlert,IPManager) values('".$ipAddrs[$i]."','".$ipPos."','".$ipAlerts[$i]."','".$_SESSION['user']['id']."')";
              $db->execute($sql);
          }
      }
      $smarty->assign('tip','提交成功');
  }
  $sql = "SELECT ti.*,tu.UserName FROM talking_ipfilter ti,talking_user tu WHERE ti.IPManager = tu.UserID";
  $ipfilters = $db->query($sql);
  $smarty->assign('ipfilters',$ipfilters);
  $smarty->display("ip_filter.html");
  $db->close();                                  
?>
